package com.nageoffer.shortlink.project.common.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("开始插入填充...");
        // 确保字段名和类型与数据库表一致
        this.strictInsertFill(metaObject, "createTime", Date::new, Date.class);
        this.strictInsertFill(metaObject, "updateTime", Date::new, Date.class);
        this.strictInsertFill(metaObject, "delFlag", Integer.class,0);
        log.info("插入填充完成，字段：createTime, updateTime, delFlag");
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("开始更新填充...");
        // 确保字段名和类型与数据库表一致
        this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
        log.info("更新填充完成，字段：updateTime");
    }
}